#pragma once

#include "IFragmentController.h"
#include <ppltasks.h>

namespace Microsoft {
	namespace Media {
		namespace FragmentedMediaSink {
			public ref class FragmentController sealed : IFragmentController
			{
			private:
				Windows::Foundation::TimeSpan fragmentSize;
				Windows::Media::MediaProperties::IMediaEncodingProperties^ encodingProperties;

			public:
				FragmentController()
				{}

				event EventHandler<Fragment^>^ FragmentCreated;

				virtual Windows::Storage::Streams::IRandomAccessStream^ StartFragment()
				{
					return ref new Windows::Storage::Streams::InMemoryRandomAccessStream();
				}

				virtual void FragmentCompleted(Fragment^ fragment)
				{
					fragment->Stream->Seek(0);
					FragmentCreated(this, fragment);
				}
				
				property Windows::Foundation::TimeSpan FragmentSize
				{
					virtual Windows::Foundation::TimeSpan FragmentSize::get()
					{
						return fragmentSize;
					}
					void FragmentSize::set(Windows::Foundation::TimeSpan value)
					{
						fragmentSize = value;
					}
				}

				property Windows::Media::MediaProperties::IMediaEncodingProperties^ EncodingProperties
				{
					virtual Windows::Media::MediaProperties::IMediaEncodingProperties^ EncodingProperties::get()
					{
						return encodingProperties;
					}
					void EncodingProperties::set(Windows::Media::MediaProperties::IMediaEncodingProperties^ value)
					{
						encodingProperties = value;
					}
				}
			};
		}
	}
}